//
//  SkuShowModel.m
//  sensen_ios
//
//  Created by pro on 16/3/9.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "SkuIdModel.h"

@implementation SkuIdModel

- (instancetype)initWithDic:(NSDictionary *)dic {
    
    if (self = [super init]) {
        
        _sid = dic[@"id"];
        _vidAry = dic[@"vid"];

    }
    
    return self;
}

- (NSMutableArray *)keyValueList{
    
    if (_keyValueList == nil) {
        _keyValueList = [[NSMutableArray alloc] initWithCapacity:0];
        if (self.vidAry != nil  && self.sid != nil ) {
            
            for (NSInteger i = 0 ; i < self.vidAry.count; i ++) {
                NSString * key = [NSString stringWithFormat:@"%@:%@",self.sid,self.vidAry[i]];
                [_keyValueList addObject:key];
            }
        }
    }
    return _keyValueList;
}

// 获得key：Value 下标
-(NSInteger) getKeyValueIndex:(NSString *)keyValue{
    
    if (self.keyValueList == nil || self.keyValueList.count == 0 ) {
        return -1;
    }
    
    for (NSInteger i = 0; i < self.keyValueList.count; i ++) {
        
        NSString * key = [self.keyValueList objectAtIndex:i];
        
        if ([key isEqualToString:keyValue]) {
            return i;
        }
    }
    return -1;
}

// 获得key：Value 下标
-(NSInteger) getKeyIndex:(NSString *)key{
    
    if (self.vidAry == nil || self.vidAry.count == 0 ) {
        return -1;
    }
    
    for (NSInteger i = 0; i < self.vidAry.count; i ++) {
        
        NSString * keystr = [self.vidAry objectAtIndex:i];
        
        if ([key isEqualToString:keystr]) {
            return i;
        }
    }
    return -1;
}

@end
